'use strict';

var _ = require('underscore');
var resJson = require('../utils/resJson.js');
var Promise = require('bluebird');
var http = require('http');
var request = require('superagent');

var controller = {

};


//处理请求
controller.request = {
  method: 'post',
  action: function(req, res, next) {
    var data = req.body;
    if (data) {
      var sendData = (data.method.toUpperCase() === "GET" || data.method.toUpperCase() === "DELETE") ? null : data.requestData;
      request(data.method.toUpperCase(), data.url)
        .set(data.requestHeader || {})
        .send(sendData)
        .end(function(err, result) {
          return resJson(res, result);
        });
    } else {
      return resJson(res, null, '请提交正确的数据！');
    }
  }
};


module.exports = controller;
